<?php
namespace app\api\validate;

use think\Validate;

class User extends Validate
{
	// 定义验证规则
	protected $rule = [
        'username'     => 'require|max:25',
        'email'    => 'email',
        'phone'    => 'require|mobile',
        'password' => 'require',
        'code'     => 'require',
        'new_pwd'  => 'require'
    ];
    // 定义错误提示消息
    protected $message = [
        'username.require'  => '用户名必须',
        'username.max'      => '名称最多不能超过25个字符',
        'email'             => '邮箱格式错误', 
        'phone.require'     => '手机号必须',
        'phone.mobile'      => '手机号格式错误',
        'password'          => '密码必须',
        'code'              => '验证码必须',
        'new_pwd'           => '新密码必须'
    ];
    // 定义验证场景，比如登陆和注册所要验证的字段就不同
    protected $scene = [
        'register'  =>  ['username','email','phone','password','code'],
        'login'     =>  ['username','password','code'],
        'password'  =>  ['password','new_pwd']
    ];
}